/*===========================================================================+
 |   Copyright (c) 2001, 2005 Oracle Corporation, Redwood Shores, CA, USA    |
 |                         All rights reserved.                              |
 +===========================================================================+
 |  HISTORY                                                                  |
 +===========================================================================*/
package xxhci.oracle.apps.xxierp.PDSPSample.webui;

import java.io.Serializable;

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;

import oracle.jbo.Row;


/**
 * Controller for ...
 */
public class CreatePD_CO extends OAControllerImpl
{
  public static final String RCS_ID="$Header$";
  public static final boolean RCS_ID_RECORDED =
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

  /**
   * Layout and page setup logic for a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
               
                  
      String paramPersonAction=pageContext.getParameter("xxierpParamActionOnPerson");
      String paramPersonId=pageContext.getParameter("xxierpParamPersonId");
      
        OAApplicationModule am =
                             pageContext.getApplicationModule(webBean);
      Serializable personParamList[]={paramPersonAction,paramPersonId};
      
      
      
      
      am.invokeMethod("getViewObj");
      OAViewObject empVO = (OAViewObject)am.findViewObject("ViewObj");
      Row row[] = empVO.getAllRowsInRange();
      int i = row.length;
      
      if(paramPersonAction!=null && paramPersonAction.equals("CreatePerson")) 
      { 
        
          am.invokeMethod("createPersonMethod",personParamList);
      
      }
     else if(paramPersonAction!=null && paramPersonAction.equals("UpdatePerson")) 
      { 
      am.invokeMethod("updatePersonMethod",personParamList);
      
      }
  }

  /**
   * Procedure to handle form submissions for form elements in
   * a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
      OAApplicationModule am = pageContext.getApplicationModule(webBean);
      
      
      if (pageContext.getParameter("event").equalsIgnoreCase("Cancel"))
      {
      System.out.println("EmpSearchCO: processing create/update");
      pageContext.setForwardURL("OA.jsp?page=/xxhci/oracle/apps/XXIERP/PDSPSample/webui/SearchPD_PG",
      null,
      OAWebBeanConstants.KEEP_MENU_CONTEXT,
      null, null, true,
      OAWebBeanConstants.ADD_BREAD_CRUMB_YES,
      OAWebBeanConstants.IGNORE_MESSAGES);
      } 
             
      //  Insert Row without Sequence
    else if (pageContext.getParameter("event").equalsIgnoreCase("Apply"))
      {
              am.invokeMethod("savePersonToDatabase");
      }      
      
  }
}
                